﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.Serialization;

namespace BaiTu.ConfigInfo
{
    public class DataSettingsConfigInfo : BaseConfigInfo
    {
        public DataSettingsConfigInfo()
        {
            //_rawDataSettings = new Dictionary<string, string>();
        }
        private string _dataProvider = "sqlserver";
        public string DataProvider {
            get
            {
                return _dataProvider;
            }
            set
            {
                _dataProvider = value;
            }
        }
        private string _dataConnectionString = "server=127.0.0.1;initial catalog=test;uid=sa;pwd=yuanjinzhou";
        public string DataConnectionString
        {
            get
            {
                return _dataConnectionString;
            }
            set
            {
                _dataConnectionString = value;
            }
        }
        //[NonSerialized]
        //private Dictionary<string, string> _rawDataSettings;
        //public Dictionary<string, string> RawDataSettings {
        //    get
        //    {
        //        return _rawDataSettings;
        //    }
        //    private set
        //    {
        //        _rawDataSettings = value;
        //    }
        //}

        private bool? _isDataBaseInstalled = false;
        public bool? IsDataBaseInstalled {
            get
            {
                if (_isDataBaseInstalled.HasValue == false || _isDataBaseInstalled == null)
                {
                    return false;
                }
                return _isDataBaseInstalled;
            }
            set
            {
                _isDataBaseInstalled = value;
            }
        }
        private string _dataBaseName = "BaiTu";
        /// <summary>
        /// 数据库名称 默认为BaiTu
        /// </summary>
        public string DataBaseName
        {
            get
            {
                return _dataBaseName;
            }
            set
            {
                _dataBaseName = value;
            }
        }

        private bool? _createNewDataBase = false;
        /// <summary>
        /// 是否强制重新创建数据库
        /// </summary>
        public bool? CreateNewDataBase {
            get
            {
                return _createNewDataBase.HasValue?_createNewDataBase.Value:false;
            }
            set
            {
                _createNewDataBase = value;
            }
        }

        private int _maxPoolSize = 1;
        /// <summary>
        /// 链接池大小
        /// </summary>
        public int MaxPoolSize
        {
            get
            {
                return _maxPoolSize;
            }
            set
            {
                _maxPoolSize = value;
            }
        }
        private bool? _isLog = false;
        /// <summary>
        /// 是否记录日志
        /// </summary>
        public bool? IsLog
        {
            get
            {
                return _isLog.HasValue ? _isLog.Value : false;
            }
            set
            {
                _isLog = value;
            }
        }
        private string _logPath = "";
        /// <summary>
        /// 日志路径
        /// </summary>
        public string LogPath
        {
            get
            {
                return _logPath;
            }
            set
            {
                _logPath = value;
            }
        }
        public bool IsValid()
        {
            return !String.IsNullOrEmpty(this.DataProvider) && !String.IsNullOrEmpty(this.DataConnectionString);
        }
    }
}
